%compare performance between dikjstra,ROMER and modified threshold ROMER
%show statistics as a function of ROMER alpha (with normal ROMER algo)

number_of_nodes = 30;
params = ParamsSingleton.instance();

%simulation params
router_type = params.router_type_ROMER;
params.simulation_time_in_msec = 1000;
params.clock_tick_delta_in_msec = 100;

params.ROMER_threshold_power = 2;
params.should_use_constant_forward_probability = true;
params.constant_forward_probability = 0.6;

num_of_ticks_to_deposit_packets = 10;
ticks_to_deposit_packets = 1:num_of_ticks_to_deposit_packets;

packet_size_in_bytes = 500;
number_of_packets_to_deposit_in_each_tick = 1;
%%%%%%%%%%%%%%%%%%%%%%%%

source_node_id = 26;
dest_node_id = 13;

SingletonInitializer.create_all_singletons();

alpha_vector = 0:0.2:3;

topology_file_name = ['topology_', num2str(number_of_nodes), '_nodes.mat'];

%simulation statistics - ROMER
romer_delivery_rates_vector = zeros(1, length(alpha_vector));
romer_number_of_different_paths_vector = zeros(1, length(alpha_vector));
romer_network_load = zeros(1, length(alpha_vector));

for i = 1:length(alpha_vector)
    params.romer_alpha = alpha_vector(i);
    
    SingletonInitializer.reinit_all_singletons();
    topology = Topology.read_topology_from_file(topology_file_name, router_type);
    
    statistics = Simulator.run_single_depositor_in_unloaded_network(topology, source_node_id, dest_node_id, packet_size_in_bytes, number_of_packets_to_deposit_in_each_tick, ticks_to_deposit_packets);
    
    romer_number_of_different_paths_vector(i) = statistics.number_of_disjoint_paths;
    romer_delivery_rates_vector(i) = statistics.delivery_rate;
    romer_network_load(i) = statistics.avg_network_load;
end

%simulation statistics - ROMER (modified)
modified_romer_delivery_rates_vector = zeros(1, length(alpha_vector));
modified_romer_number_of_different_paths_vector = zeros(1, length(alpha_vector));
modified_romer_network_load = zeros(1, length(alpha_vector));

modified_ROMER_threshold_value = 1.5;
params.ROMER_threshold_power = modified_ROMER_threshold_value;
for i = 1:length(alpha_vector)
    params.romer_alpha = alpha_vector(i);
    
    SingletonInitializer.reinit_all_singletons();
    topology = Topology.read_topology_from_file(topology_file_name, router_type);
    
    statistics = Simulator.run_single_depositor_in_unloaded_network(topology, source_node_id, dest_node_id, packet_size_in_bytes, number_of_packets_to_deposit_in_each_tick, ticks_to_deposit_packets);
    
    modified_romer_number_of_different_paths_vector(i) = statistics.number_of_disjoint_paths;
    modified_romer_delivery_rates_vector(i) = statistics.delivery_rate;
    modified_romer_network_load(i) = statistics.avg_network_load;
end



% draw the results

figure();
grid minor;
hold on;
xlabel('Romer alpha');
ylabel('Number of disjoint paths');
title('number of disjoint routing paths = f(alpha)');
plot(alpha_vector, romer_number_of_different_paths_vector, 'Color', 'blue');
plot(alpha_vector, modified_romer_number_of_different_paths_vector, 'Color', 'red');
hold off;

figure();
grid minor;
hold on;
xlabel('Romer alpha');
ylabel('Delivery Ratio (%)');
title('DeliveryRatio = f(RomerAlpha)');
plot(alpha_vector, romer_delivery_rates_vector, 'Color', 'blue');
plot(alpha_vector, modified_romer_delivery_rates_vector, 'Color', 'blue');
hold off;

figure();
grid minor;
hold on;
xlabel('Romer alpha');
ylabel('avg network load (KB)');
title('avg network load = f(alpha)');
plot(alpha_vector, modified_romer_network_load, 'Color', 'blue');
hold off;
